home *** CD-ROM | disk | FTP | other *** search
/ Champak 120 / Vol 120.iso / games / fratboy_.swf / scripts / frame_954 / DoAction.as
Text File  |  2010-11-09  |  31KB  |  969 lines

  1. function kaplyaMove()
  2. {
  3.    this._x += this.prirostX;
  4.    this._y += this.prirostY;
  5.    this.prirostX /= 2;
  6.    this.prirostY /= 2;
  7.    this._alpha -= 13;
  8.    if(this._alpha <= -100)
  9.    {
  10.       this.swapDepths(99999);
  11.       removeMovieClip(this);
  12.    }
  13. }
  14. function razriv(xx, yy, amount)
  15. {
  16.    i = 0;
  17.    while(i < amount)
  18.    {
  19.       _root.kaplyaCounter = _root.kaplyaCounter + 1;
  20.       _root.attachMovie("kaplya","kaplya" + kaplyaCounter,_root.getNextHighestDepth(),{_x:xx,_y:yy});
  21.       eval("kaplya" + kaplyaCounter).prirostX = random(30) - 15;
  22.       eval("kaplya" + kaplyaCounter).prirostY = random(30) - 15;
  23.       eval("kaplya" + kaplyaCounter).onEnterFrame = kaplyaMove;
  24.       eval("kaplya" + kaplyaCounter).counter = 20;
  25.       eval("kaplya" + kaplyaCounter)._xscale = eval("kaplya" + i)._yscale = random(70) + 70;
  26.       i++;
  27.    }
  28. }
  29. function missileMove()
  30. {
  31.    this._x -= (this._x - eval("a" + this.trg).mc._x) / this.toTarget;
  32.    this._y -= (this._y - eval("a" + this.trg).mc._y + 30) / this.toTarget;
  33.    this.toTarget--;
  34.    if(eval("a" + this.trg).mc._x == undefined)
  35.    {
  36.       this.swapDepths(99999);
  37.    }
  38.    removeMovieClip(this);
  39.    if(this.sensor.hitTest(eval("a" + this.trg).mc))
  40.    {
  41.       if((this.towerType == 1 || this.towerType == 6) && creatureType == 2)
  42.       {
  43.          eval("a" + this.trg).mc.estimatedDamage -= missileDamage[this.towerType][this.level - 1] / 2;
  44.          eval("a" + this.trg).mc.health -= missileDamage[this.towerType][this.level - 1] / 2;
  45.       }
  46.       else
  47.       {
  48.          eval("a" + this.trg).mc.estimatedDamage -= missileDamage[this.towerType][this.level - 1];
  49.          eval("a" + this.trg).mc.health -= missileDamage[this.towerType][this.level - 1];
  50.       }
  51.       if(this.towerType == 5)
  52.       {
  53.          eval("a" + this.trg).mc.willbeTrapped = false;
  54.          if(eval("a" + this.trg).mc.health <= 0)
  55.          {
  56.             eval("a" + this.trg).mc.trapped = true;
  57.          }
  58.          else
  59.          {
  60.             eval("a" + this.trg).mc.trapDelay = _root.trapDelay[this.level - 1];
  61.          }
  62.       }
  63.       this.swapDepths(99999);
  64.       removeMovieClip(this);
  65.       this.swapDepths(99995);
  66.       removeMovieClip(this);
  67.    }
  68. }
  69. function towerMove()
  70. {
  71.    var snd = new Sound(this);
  72.    this.swap();
  73.    if(activeTower != this.num)
  74.    {
  75.       this.sensor._visible = false;
  76.       this.tower.transform.colorTransform = unSelectedTower;
  77.    }
  78.    this.i = 1;
  79.    while(this.i < creatureNum)
  80.    {
  81.       if(this.sensor.hitTest(eval("_global.a" + this.i).mc._x,eval("_global.a" + this.i).mc._y,true) && this.busy != true && eval("_global.a" + this.i).mc.health > eval("_global.a" + this.i).mc.estimatedDamage && (eval("_global.a" + this.i).mc.estimatedDamage == 0 || eval("_global.a" + this.i).mc.health > missileDamage[this.towerType][this.level - 1] + eval("_global.a" + this.i).mc.estimatedDamage) && (this.towerType != 5 || eval("_global.a" + this.i).mc.willbeTrapped != true) && (this.towerType != 4 || creatureType == 4) && (creatureType != 4 || this.towerType != 2 && this.towerType != 3))
  82.       {
  83.          this.busy = true;
  84.          missilesNum++;
  85.          if(this.towerType != 3)
  86.          {
  87.             if(creatureType == 2 && (this.towerType == 1 || this.towerType == 6))
  88.             {
  89.                eval("_global.a" + this.i).mc.estimatedDamage += missileDamage[this.towerType][this.level - 1] / 2;
  90.             }
  91.             else
  92.             {
  93.                eval("_global.a" + this.i).mc.estimatedDamage += missileDamage[this.towerType][this.level - 1];
  94.             }
  95.             _root.attachMovie("missile" + this.towerType,"missile" + missilesNum,_root.getNextHighestDepth(),{_x:this._x,_y:this._y - 20});
  96.             eval("missile" + missilesNum).onEnterFrame = missileMove;
  97.             eval("missile" + missilesNum).trg = this.i;
  98.             eval("missile" + missilesNum).toTarget = missileSpeed[this.towerType - 1];
  99.             if(this.towerType == 1 || this.towerType == 6)
  100.             {
  101.                eval("missile" + missilesNum)._rotation = Math.atan((this._y - eval("a" + this.i).mc._y) / (this._x - eval("a" + this.i).mc._x)) * 180 / 3.141592653589793 + 90;
  102.             }
  103.             eval("missile" + missilesNum).towerType = this.towerType;
  104.             eval("missile" + missilesNum).level = this.level;
  105.             if(this.towerType == 4)
  106.             {
  107.                this.tower.gotoAndPlay(2);
  108.                snd.attachSound("_zvezdochka");
  109.                snd.start();
  110.             }
  111.             else if(this.towerType == 5)
  112.             {
  113.                snd.attachSound("_setka");
  114.                snd.start();
  115.             }
  116.             if(this.towerType == 5)
  117.             {
  118.                eval("_global.a" + this.i).mc.willbeTrapped = true;
  119.             }
  120.          }
  121.          else
  122.          {
  123.             this.field._width = this.field._height = this.sensor._width / 2;
  124.             this.field.gotoAndPlay(2);
  125.             this.i = 1;
  126.             while(this.i < _root.creatureNum)
  127.             {
  128.                if(this.sensor.hitTest(eval("_global.a" + this.i).mc._x,eval("_global.a" + this.i).mc._y,true) && (eval("_global.a" + this.i).mc.estimatedDamage == 0 || eval("_global.a" + this.i).mc.health > missileDamage[this.towerType][this.level - 1] + eval("_global.a" + this.i).mc.estimatedDamage))
  129.                {
  130.                   if(creatureType == 1)
  131.                   {
  132.                      eval("_global.a" + this.i).mc.health -= missileDamage[this.towerType][this.level - 1] / 2;
  133.                   }
  134.                   else
  135.                   {
  136.                      eval("_global.a" + this.i).mc.health -= missileDamage[this.towerType][this.level - 1];
  137.                   }
  138.                }
  139.                this.i = this.i + 1;
  140.             }
  141.          }
  142.          this.i = creatureNum;
  143.          this.counter = 0;
  144.       }
  145.       this.i = this.i + 1;
  146.    }
  147.    if(this.busy == true)
  148.    {
  149.       if(this.counter < towerDelay[this.towerType][this.level - 1])
  150.       {
  151.          this.counter = this.counter + 1;
  152.       }
  153.       else
  154.       {
  155.          this.busy = false;
  156.       }
  157.    }
  158. }
  159. function cursorMove()
  160. {
  161.    this._x = Math.round((_xmouse - cellSize) / 10) * 10;
  162.    this._y = Math.round((_ymouse - cellSize) / 10) * 10;
  163. }
  164. function creatureMove()
  165. {
  166.    if(this.health <= 0)
  167.    {
  168.       if(this.trapped != true)
  169.       {
  170.          var snd = new Sound(this);
  171.          snd.attachSound("_creature" + creatureType + "Death" + (random(3) + 1));
  172.          snd.start();
  173.       }
  174.       if(this.trapped == true)
  175.       {
  176.          if(this.umer != true)
  177.          {
  178.             this.umer = true;
  179.             this.cr.gotoAndStop("catched");
  180.             gold += creatureCost[creatureGroupNum - 1] * 2;
  181.             this.t = getTimer();
  182.          }
  183.          if(getTimer() - this.t > 900)
  184.          {
  185.             this.swapDepths(99999);
  186.             removeMovieClip(this);
  187.             totalCatched++;
  188.          }
  189.       }
  190.       else
  191.       {
  192.          _root.razriv(this._x,this._y - 15,25);
  193.          this.swapDepths(99999);
  194.          removeMovieClip(this);
  195.          totalKilled++;
  196.          gold += creatureCost[creatureGroupNum - 1];
  197.       }
  198.       _root.allDead = true;
  199.       next._alpha = 100;
  200.       p._alpha = 100;
  201.       i = 1;
  202.       while(i < creatureNum)
  203.       {
  204.          if(eval("_global.a" + i).mc._x != undefined)
  205.          {
  206.             i = _root.creatureNum;
  207.             _root.allDead = false;
  208.             next._alpha = 20;
  209.             p._alpha = 20;
  210.          }
  211.          i++;
  212.       }
  213.    }
  214.    this.healthBar._xscale = this.health * 100 / this.fullHealth;
  215.    i = 0;
  216.    while(i < creatureNum)
  217.    {
  218.       if(this.newDir == 4 && eval("_global.a" + i).mc.newDir != 8 || this.newDir == 8 && eval("_global.a" + i).mc.newDir != 4)
  219.       {
  220.          if(this._y > eval("_global.a" + i + ".mc")._y && this.getDepth() < eval("_global.a" + i + ".mc").getDepth())
  221.          {
  222.             this.swapDepths("_global.a" + i + ".mc");
  223.          }
  224.          if(this._y < eval("_global.a" + i + ".mc")._y && this.getDepth() > eval("_global.a" + i + ".mc").getDepth())
  225.          {
  226.             this.swapDepths("_global.a" + i + ".mc");
  227.          }
  228.       }
  229.       i++;
  230.    }
  231. }
  232. function creatureGen(num)
  233. {
  234.    zast = false;
  235.    currentCreepWave++;
  236.    tossTowers();
  237.    _root.creatureNum = 0;
  238.    _root.allDead = false;
  239.    _root.next._alpha = 20;
  240.    _root.p._alpha = 20;
  241.    var snd = new Sound(this);
  242.    snd.attachSound("_cr" + creatureType + "appear1");
  243.    snd.start();
  244.    if(creatureType >= 5)
  245.    {
  246.       creatureType = 1;
  247.       creatureGroupNum++;
  248.    }
  249.    if(num == undefined)
  250.    {
  251.       num = 1;
  252.    }
  253.    _root.creatureNum = 1;
  254.    while(_root.creatureNum <= num)
  255.    {
  256.       set("_global.a" + _root.creatureNum,new Agent({x:3,y:-1 - _root.creatureNum * spaceBetweenCreatures,map:map}));
  257.       eval("_global.a" + _root.creatureNum).num = _root.creatureNum;
  258.       eval("_global.a" + _root.creatureNum).mc.num = _root.creatureNum;
  259.       eval("_global.a" + _root.creatureNum).mc.trapDelay = 0;
  260.       eval("_global.a" + _root.creatureNum).mc.cacheAsBitmap = true;
  261.       eval("_global.a" + _root.creatureNum).mc.gotoAndStop(creatureType);
  262.       eval("_global.a" + _root.creatureNum).mc.estimatedDamage = 0;
  263.       eval("_global.a" + _root.creatureNum).mc.health = groupHealth[creatureGroupNum - 1];
  264.       eval("_global.a" + _root.creatureNum).mc.fullHealth = groupHealth[creatureGroupNum - 1];
  265.       _root.creatureNum = _root.creatureNum + 1;
  266.    }
  267.    _root.pathFinder();
  268. }
  269. function tossTowers()
  270. {
  271.    i = 0;
  272.    while(i <= towersNum)
  273.    {
  274.       eval("tower" + i).swapDepths(10000 + eval("tower" + i)._y * 10 + eval("tower" + i)._x / 10);
  275.       i++;
  276.    }
  277. }
  278. function placeSquare(xx, yy, color)
  279. {
  280.    obstCounter++;
  281.    if(color == undefined)
  282.    {
  283.       color = 5734680;
  284.    }
  285.    this.createEmptyMovieClip("square_mc" + obstCounter,this.getNextHighestDepth());
  286.    eval("square_mc" + obstCounter)._x = xx;
  287.    eval("square_mc" + obstCounter)._y = yy;
  288.    eval("square_mc" + obstCounter).beginFill(color);
  289.    eval("square_mc" + obstCounter).moveTo(0,0);
  290.    eval("square_mc" + obstCounter).lineTo(squareSize,0);
  291.    eval("square_mc" + obstCounter).lineTo(squareSize,squareSize);
  292.    eval("square_mc" + obstCounter).lineTo(0,squareSize);
  293.    eval("square_mc" + obstCounter).lineTo(0,0);
  294.    eval("square_mc" + obstCounter).endFill();
  295. }
  296. function buttonsRollOut()
  297. {
  298.    _root.msg1 = undefined;
  299.    _root.msg2 = undefined;
  300. }
  301. function clearAll()
  302. {
  303.    globalSound.stop();
  304.    target.swapDepths(99999);
  305.    removeMovieClip(target);
  306.    towerTable.swapDepths(99999);
  307.    towerTable.removeMovieClip();
  308.    cursor.swapDepths(99999);
  309.    cursor.removeMovieClip();
  310.    i = 0;
  311.    while(i <= creatureNum)
  312.    {
  313.       eval("a" + i).mc.swapDepths(99999);
  314.       eval("a" + i).mc.removeMovieClip();
  315.       delete ("a" + i);
  316.       i++;
  317.    }
  318.    i = 0;
  319.    while(i <= towersNum)
  320.    {
  321.       eval("tower" + i).swapDepths(99999);
  322.       eval("tower" + i).removeMovieClip();
  323.       i++;
  324.    }
  325. }
  326. function availableorNot()
  327. {
  328.    i = 1;
  329.    while(i < 8)
  330.    {
  331.       if(gold < towerCost[i][0])
  332.       {
  333.          eval("twr" + i).transform.colorTransform = unavailable;
  334.       }
  335.       else
  336.       {
  337.          eval("twr" + i).transform.colorTransform = unSelectedTower;
  338.       }
  339.       i++;
  340.    }
  341. }
  342. function pathFinder()
  343. {
  344.    var mx = 30;
  345.    var my = 41;
  346.    if(map[my][mx] == 1 || map[my][mx] == undefined)
  347.    {
  348.       trace("tile not allowed");
  349.       return false;
  350.    }
  351.    var target = this.attachMovie("target","target",1,{_x:mx * 10,_y:my * 10});
  352.    a1.onArrive = function()
  353.    {
  354.       target.swapDepths(99999);
  355.       target.removeMovieClip();
  356.    };
  357.    i = 1;
  358.    while(i < _root.creatureNum)
  359.    {
  360.       eval("a" + i).walkTo(mx,my);
  361.       eval("a" + i).onArrive = function()
  362.       {
  363.          eval("a" + i).mc.swapDepths(99999);
  364.          eval("a" + i).mc.removeMovieClip();
  365.          rp--;
  366.          _root.allDead = true;
  367.          next._alpha = 100;
  368.          i = 1;
  369.          while(i < creatureNum)
  370.          {
  371.             if(eval("_global.a" + i).mc._x != undefined)
  372.             {
  373.                i = _root.creatureNum;
  374.                _root.allDead = false;
  375.                next._alpha = 20;
  376.             }
  377.             i++;
  378.          }
  379.       };
  380.       i++;
  381.    }
  382. }
  383. _global.Agent = function(initObj)
  384. {
  385.    for(var _loc3_ in initObj)
  386.    {
  387.       this[_loc3_] = initObj[_loc3_];
  388.    }
  389.    this.attachMe();
  390. };
  391. o = Agent.prototype;
  392. o.attachMe = function()
  393. {
  394.    if(_root.currentCreepWave > 12)
  395.    {
  396.       if(_root.currentCreepWave % 12 == 8)
  397.       {
  398.          _root.ag = "agent2";
  399.       }
  400.       else if(_root.currentCreepWave % 12 == 0)
  401.       {
  402.          _root.ag = "agent3";
  403.       }
  404.       else if(_root.currentCreepWave % 12 == 4)
  405.       {
  406.          _root.ag = "agent";
  407.       }
  408.    }
  409.    this.mc = _root.attachMovie(_root.ag,"cr" + _root.creatureNum,900 + _root.creatureNum,{_x:this.x * 10 + 10,_y:this.y * 10 + 10});
  410.    this.mc.onEnterFrame = creatureMove;
  411. };
  412. o.walkTo = function(tx, ty)
  413. {
  414.    this.tx = tx;
  415.    this.ty = ty;
  416.    if(this.loop !== this.walking)
  417.    {
  418.       this.dir = 0;
  419.       this.dir = this.getApproximatedDirection();
  420.    }
  421.    this.visitedNodes = [];
  422.    this.loop = this.walking;
  423. };
  424. o.getApproximatedDirection = function()
  425. {
  426.    var _loc5_ = this.map;
  427.    var _loc4_ = this.x;
  428.    var _loc3_ = this.y;
  429.    var _loc23_ = this.dir;
  430.    var _loc22_ = this.tx;
  431.    var _loc20_ = this.ty;
  432.    var _loc9_ = _loc22_ - _loc4_;
  433.    var _loc8_ = _loc20_ - _loc3_;
  434.    var _loc10_ = Math.abs;
  435.    var _loc13_ = _loc10_(_loc9_);
  436.    var _loc12_ = _loc10_(_loc8_);
  437.    var _loc16_ = _loc13_ >= _loc12_;
  438.    var _loc15_ = _loc12_ >= _loc13_;
  439.    var _loc2_ = [];
  440.    var _loc14_ = _loc5_[_loc3_];
  441.    if((~_loc14_[_loc4_ + 1]) & 1 && _loc23_ != 2)
  442.    {
  443.       var _loc25_ = undefined;
  444.       if((_loc25_ = _loc9_ >= 0) && _loc16_)
  445.       {
  446.          _loc2_.push({dir:1,value:3});
  447.       }
  448.       else if(_loc25_)
  449.       {
  450.          _loc2_.push({dir:1,value:2});
  451.       }
  452.       else if(_loc23_ == 1)
  453.       {
  454.          _loc2_.push({dir:1,value:1});
  455.       }
  456.       else
  457.       {
  458.          _loc2_.push({dir:1,value:0});
  459.       }
  460.    }
  461.    if((~_loc14_[_loc4_ - 1]) & 1 && _loc23_ != 1)
  462.    {
  463.       var _loc21_ = undefined;
  464.       if((_loc21_ = _loc9_ <= 0) && _loc16_)
  465.       {
  466.          _loc2_.push({dir:2,value:3});
  467.       }
  468.       else if(_loc21_)
  469.       {
  470.          _loc2_.push({dir:2,value:2});
  471.       }
  472.       else if(_loc23_ == 2)
  473.       {
  474.          _loc2_.push({dir:2,value:1});
  475.       }
  476.       else
  477.       {
  478.          _loc2_.push({dir:2,value:0});
  479.       }
  480.    }
  481.    if((~_loc5_[_loc3_ + 1][_loc4_]) & 1 && _loc23_ != 8)
  482.    {
  483.       var _loc24_ = undefined;
  484.       if((_loc24_ = _loc8_ >= 0) && _loc15_)
  485.       {
  486.          _loc2_.push({dir:4,value:3});
  487.       }
  488.       else if(_loc24_)
  489.       {
  490.          _loc2_.push({dir:4,value:2});
  491.       }
  492.       else if(_loc23_ == 4)
  493.       {
  494.          _loc2_.push({dir:4,value:1});
  495.       }
  496.       else
  497.       {
  498.          _loc2_.push({dir:4,value:0});
  499.       }
  500.    }
  501.    if((~_loc5_[_loc3_ - 1][_loc4_]) & 1 && _loc23_ != 4)
  502.    {
  503.       var _loc19_ = undefined;
  504.       if((_loc19_ = _loc8_ <= 0) && _loc15_)
  505.       {
  506.          _loc2_.push({dir:8,value:3});
  507.       }
  508.       else if(_loc19_)
  509.       {
  510.          _loc2_.push({dir:8,value:2});
  511.       }
  512.       else if(_loc23_ == 8)
  513.       {
  514.          _loc2_.push({dir:8,value:1});
  515.       }
  516.       else
  517.       {
  518.          _loc2_.push({dir:8,value:0});
  519.       }
  520.    }
  521.    _loc2_.sortOn("value");
  522.    var _loc17_ = _loc2_.length;
  523.    var _loc11_ = _loc2_[_loc17_ = _loc17_ - 1];
  524.    var _loc18_ = _loc2_[_loc17_ = _loc17_ - 1];
  525.    if(_loc11_.value == _loc18_.value)
  526.    {
  527.       var _loc7_ = _loc11_.dir + _loc18_.dir;
  528.       if(_loc7_ == 5 && (~_loc5_[_loc3_ + 1][_loc4_ + 1]) & 1)
  529.       {
  530.          return 5;
  531.       }
  532.       if(_loc7_ == 6 && (~_loc5_[_loc3_ + 1][_loc4_ - 1]) & 1)
  533.       {
  534.          return 6;
  535.       }
  536.       if(_loc7_ == 9 && (~_loc5_[_loc3_ - 1][_loc4_ + 1]) & 1)
  537.       {
  538.          return 9;
  539.       }
  540.       if(_loc7_ == 10 && (~_loc5_[_loc3_ - 1][_loc4_ - 1]) & 1)
  541.       {
  542.          return 10;
  543.       }
  544.    }
  545.    var _loc6_ = _loc2_.pop().dir;
  546.    if(_loc6_ == this.visitedNodes[_loc3_][_loc4_])
  547.    {
  548.       alert += "\rvisited";
  549.       _loc6_ = _loc2_.pop().dir;
  550.    }
  551.    this.mc.newDir = _loc6_;
  552.    if(_loc23_ != _loc6_)
  553.    {
  554.       if(this.visitedNodes[_loc3_] == undefined)
  555.       {
  556.          this.visitedNodes[_loc3_] = [];
  557.       }
  558.       this.visitedNodes[_loc3_][_loc4_] = _loc6_;
  559.       alert += "\rmarker " + [_loc4_,_loc3_];
  560.    }
  561.    return _loc6_;
  562. };
  563. o.walking = function()
  564. {
  565.    var _loc4_ = this.dir;
  566.    var _loc3_ = this.mc;
  567.    var _loc5_ = 2;
  568.    _loc5_ = _root.speed;
  569.    if(creatureType == 3)
  570.    {
  571.       _loc5_ = 3.3333333333333335;
  572.    }
  573.    if(this.dirr != this.dir)
  574.    {
  575.       if(this.dir == 1)
  576.       {
  577.          this.mc.cr.gotoAndPlay("right");
  578.       }
  579.       else if(this.dir == 2)
  580.       {
  581.          this.mc.cr.gotoAndPlay("left");
  582.       }
  583.       else if(this.dir == 8)
  584.       {
  585.          this.mc.cr.gotoAndPlay("up");
  586.       }
  587.       else if(this.dir == 4)
  588.       {
  589.          this.mc.cr.gotoAndPlay("down");
  590.       }
  591.       this.dirr = this.dir;
  592.    }
  593.    if(this.mc.trapped != true)
  594.    {
  595.       if(this.mc.trapDelay == 0)
  596.       {
  597.          if(_loc4_ == 1)
  598.          {
  599.             _loc3_._x += _loc5_;
  600.          }
  601.          else if(_loc4_ == 2)
  602.          {
  603.             _loc3_._x -= _loc5_;
  604.          }
  605.          else if(_loc4_ == 4)
  606.          {
  607.             _loc3_._y += _loc5_;
  608.          }
  609.          else if(_loc4_ == 8)
  610.          {
  611.             _loc3_._y -= _loc5_;
  612.          }
  613.          else if(_loc4_ == 5)
  614.          {
  615.             _loc3_._x += _loc5_;
  616.             _loc3_._y += _loc5_;
  617.          }
  618.          else if(_loc4_ == 9)
  619.          {
  620.             _loc3_._x += _loc5_;
  621.             _loc3_._y -= _loc5_;
  622.          }
  623.          else if(_loc4_ == 10)
  624.          {
  625.             _loc3_._x -= _loc5_;
  626.             _loc3_._y -= _loc5_;
  627.          }
  628.          else if(_loc4_ == 6)
  629.          {
  630.             _loc3_._x -= _loc5_;
  631.             _loc3_._y += _loc5_;
  632.          }
  633.          if(_loc3_._x > 0 && _loc3_._y > 0)
  634.          {
  635.             if(_loc3_._x % 10 < 1 || _loc3_._x % 10 > 9)
  636.             {
  637.                _loc3_._x = Math.round(_loc3_._x);
  638.             }
  639.             if(_loc3_._y % 10 < 1 || _loc3_._y % 10 > 9)
  640.             {
  641.                _loc3_._y = Math.round(_loc3_._y);
  642.             }
  643.          }
  644.          if(_loc3_._y < 0)
  645.          {
  646.             if(_loc3_._y % 10 > -1 || _loc3_._y % 10 < -9)
  647.             {
  648.                _loc3_._y = Math.round(_loc3_._y);
  649.             }
  650.          }
  651.          if(_loc3_._x % 10 == 0 && _loc3_._y % 10 == 0)
  652.          {
  653.             if(_loc4_ == 1)
  654.             {
  655.                this.x += 1;
  656.             }
  657.             else if(_loc4_ == 2)
  658.             {
  659.                this.x -= 1;
  660.             }
  661.             else if(_loc4_ == 4)
  662.             {
  663.                this.y += 1;
  664.             }
  665.             else if(_loc4_ == 8)
  666.             {
  667.                this.y -= 1;
  668.             }
  669.             else if(_loc4_ == 5)
  670.             {
  671.                this.x += 1;
  672.                this.y += 1;
  673.             }
  674.             else if(_loc4_ == 9)
  675.             {
  676.                this.x += 1;
  677.                this.y -= 1;
  678.             }
  679.             else if(_loc4_ == 10)
  680.             {
  681.                this.x -= 1;
  682.                this.y -= 1;
  683.             }
  684.             else if(_loc4_ == 6)
  685.             {
  686.                this.x -= 1;
  687.                this.y += 1;
  688.             }
  689.             if(this.x == this.tx && this.y == this.ty)
  690.             {
  691.                delete this.loop;
  692.                this.onArrive();
  693.                return undefined;
  694.             }
  695.             this.dir = this.getApproximatedDirection();
  696.          }
  697.       }
  698.       else
  699.       {
  700.          this.mc.trapDelay--;
  701.       }
  702.    }
  703. };
  704. var map = Array();
  705. map[0] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  706. map[1] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  707. map[2] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  708. map[3] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  709. map[4] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  710. map[5] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  711. map[6] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  712. map[7] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  713. map[8] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  714. map[9] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  715. map[10] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  716. map[11] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  717. map[12] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  718. map[13] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  719. map[14] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  720. map[15] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  721. map[16] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  722. map[17] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  723. map[18] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  724. map[19] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  725. map[20] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  726. map[21] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  727. map[22] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  728. map[23] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  729. map[24] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1];
  730. map[25] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  731. map[26] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  732. map[27] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  733. map[28] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];
  734. map[29] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  735. map[30] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  736. map[31] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  737. map[32] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  738. map[33] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1];
  739. map[34] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1];
  740. map[35] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1];
  741. map[36] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1];
  742. map[37] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1];
  743. map[38] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1];
  744. map[39] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1];
  745. map[40] = [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1];
  746. map[41] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1];
  747. map[42] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1];
  748. map[43] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1];
  749. map[44] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3];
  750. map[45] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3];
  751. ag = "agent";
  752. obstCounter = 0;
  753. cellSize = 10;
  754. squareSize = 8;
  755. speed = 2;
  756. kaplyaCounter = 0;
  757. spaceBetweenCreatures = 2;
  758. towersNum = 0;
  759. missilesNum = 0;
  760. animationsNum = 6;
  761. creatureGroupNum = 1;
  762. gold = 600;
  763. rp = 20;
  764. tower5cost = 50;
  765. towerType = 0;
  766. next._alpha = 20;
  767. allDead = false;
  768. p.p._visible = false;
  769. creatureType = 0;
  770. delay = undefined;
  771. currentCreepWave = 0;
  772. totalKilled = 0;
  773. totalCatched = 0;
  774. pausee = false;
  775. zast = false;
  776. selectedTower = new flash.geom.ColorTransform();
  777. selectedTower.alphaMultiplier = 0.8;
  778. selectedTower.redMultiplier = 15;
  779. selectedTower.greenMultiplier = 0.4;
  780. selectedTower.blueMultiplier = 0.4;
  781. unSelectedTower = new flash.geom.ColorTransform();
  782. unSelectedTower.alphaMultiplier = 1;
  783. unSelectedTower.redMultiplier = 1;
  784. unSelectedTower.greenMultiplier = 1;
  785. unSelectedTower.blueMultiplier = 1;
  786. unavailable = new flash.geom.ColorTransform();
  787. unavailable.alphaMultiplier = 1;
  788. unavailable.redMultiplier = 0.4;
  789. unavailable.greenMultiplier = 0.4;
  790. unavailable.blueMultiplier = 0.4;
  791. var trapDelay = Array();
  792. trapDelay = [30,40,50,60,70];
  793. var groupHealth = Array();
  794. i = 0;
  795. var creatureCost = Array();
  796. xx = 2;
  797. while(xx < 100)
  798. {
  799.    groupHealth[i] = Math.round(xx * xx + i * i / 1.3) * 10;
  800.    creatureCost[i] = 10 + i;
  801.    if(groupHealth[i] > 3000)
  802.    {
  803.       groupHealth[i] += i * i * 8;
  804.    }
  805.    i++;
  806.    xx++;
  807. }
  808. var towerCost = Array();
  809. towerCost[1] = [50,100,150,200,300];
  810. towerCost[2] = [100,100,300,700,1200];
  811. towerCost[3] = [500,400,600,900,2000];
  812. towerCost[4] = [600,400,600,1000,1000];
  813. towerCost[5] = [1000,600,700,900,1200];
  814. towerCost[6] = [2000,1000,2000,2000,2000];
  815. var missileDamage = Array();
  816. missileDamage[1] = [10,20,50,100,150];
  817. missileDamage[2] = [40,80,220,500,900];
  818. missileDamage[3] = [80,180,360,640,1100];
  819. missileDamage[4] = [100,230,460,820,1200];
  820. missileDamage[5] = [100,160,250,400,700];
  821. missileDamage[6] = [100,200,400,600,800];
  822. var towerDistance = Array();
  823. towerDistance[1] = [220,230,240,250,260];
  824. towerDistance[2] = [230,240,260,280,300];
  825. towerDistance[3] = [100,110,120,130,150];
  826. towerDistance[4] = [270,280,290,330,350];
  827. towerDistance[5] = [200,220,240,260,280];
  828. towerDistance[6] = [300,310,320,330,340];
  829. var towerDelay = Array();
  830. towerDelay[1] = [24,23,22,21,20];
  831. towerDelay[2] = [30,28,26,23,20];
  832. towerDelay[3] = [25,24,22,21,20];
  833. towerDelay[4] = [20,18,15,12,10];
  834. towerDelay[5] = [50,50,45,40,35];
  835. towerDelay[6] = [4,4,4,4,4];
  836. var missileSpeed = Array();
  837. missileSpeed = [9,15,0,35,20,12];
  838. globalSound.stop();
  839. globalSound = new Sound(this);
  840. globalSound.attachSound("_music");
  841. globalSound.start(0,1000);
  842. globalSound.setVolume(100);
  843. _root.attachMovie("instr","instr",_root.getNextHighestDepth(),{_x:10,_y:9});
  844. _root.pausee = true;
  845. _root.onMouseDown = function()
  846. {
  847.    if(_root.pausee != true)
  848.    {
  849.       click = true;
  850.       i = 0;
  851.       while(i < towersNum + 1)
  852.       {
  853.          if(cursor.sensor.hitTest(eval("tower" + i)._x,eval("tower" + i)._y))
  854.          {
  855.             towerTable.swapDepths(99999);
  856.             towerTable.removeMovieClip();
  857.             snsr.swapDepths(99999);
  858.             removeMovieClip(snsr);
  859.             _root.attachMovie("snsr","snsr",_root.getNextHighestDepth(),{_x:eval("tower" + i)._x,_y:eval("tower" + i)._y});
  860.             snsr._width = eval("tower" + i)._width;
  861.             snsr._height = eval("tower" + i)._height;
  862.             activeTower = i;
  863.             towerType = 0;
  864.             cursor._visible = false;
  865.             _root.attachMovie("towerTable","towerTable",_root.getNextHighestDepth(),{_x:390,_y:155});
  866.             eval("tower" + i).tower.transform.colorTransform = selectedTower;
  867.             i = towersNum;
  868.             click = false;
  869.          }
  870.          i++;
  871.       }
  872.       if(map[cursor._y / 10][cursor._x / 10] == 1 && map[cursor._y / 10 - 1][cursor._x / 10] == 1 && map[cursor._y / 10][cursor._x / 10 - 1] == 1 && map[cursor._y / 10 - 1][cursor._x / 10 - 1] == 1 && gold >= towerCost[towerType][0] && towerType != 0 && click == true)
  873.       {
  874.          towersNum++;
  875.          gold -= towerCost[towerType][0];
  876.          _root.attachMovie("tower" + towerType,"tower" + towersNum,10000 + cursor._y * 10 + cursor._x / 10,{_x:_root.cursor._x + 9,_y:_root.cursor._y + 12});
  877.          if(towerType == 5)
  878.          {
  879.             towerCost[5][0] += 250;
  880.          }
  881.          map[Math.round(cursor._y / 10)][Math.round(cursor._x / 10)] = map[Math.round(cursor._y / 10) - 1][Math.round(cursor._x / 10)] = map[Math.round(cursor._y / 10)][Math.round(cursor._x / 10) - 1] = map[Math.round(cursor._y / 10) - 1][Math.round(cursor._x / 10) - 1] = 3;
  882.          eval("tower" + towersNum).num = towersNum;
  883.          eval("tower" + towersNum).towerType = towerType;
  884.          eval("tower" + towersNum).onEnterFrame = towerMove;
  885.          eval("tower" + towersNum).level = 1;
  886.          eval("tower" + towersNum).sensor._height = eval("tower" + towersNum).sensor._width = towerDistance[towerType][0];
  887.          activeTower = 0;
  888.          snsr.swapDepths(99999);
  889.          removeMovieClip(snsr);
  890.          towerTable.swapDepths(99999);
  891.          towerTable.removeMovieClip();
  892.          click = false;
  893.       }
  894.       if(towerTable.hitTest(_xmouse,_ymouse,false))
  895.       {
  896.          click = false;
  897.       }
  898.       if(click == true)
  899.       {
  900.          snsr.swapDepths(99999);
  901.          removeMovieClip(snsr);
  902.          activeTower = 0;
  903.          towerType = 0;
  904.          click = false;
  905.          towerTable.swapDepths(99999);
  906.          towerTable.removeMovieClip();
  907.          cursor._visible = false;
  908.       }
  909.    }
  910. };
  911. MovieClip.prototype.swap = function()
  912. {
  913.    i = 1;
  914.    while(i < creatureNum)
  915.    {
  916.       if(this._y > eval("a" + i).mc._y && this.getDepth() < eval("a" + i).mc.getDepth())
  917.       {
  918.          this.swapDepths(eval("a" + i).mc);
  919.       }
  920.       if(this._y < eval("a" + i).mc._y && this.getDepth() > eval("a" + i).mc.getDepth())
  921.       {
  922.          this.swapDepths(eval("a" + i).mc);
  923.       }
  924.       i++;
  925.    }
  926. };
  927. i = 1;
  928. while(i < 5)
  929. {
  930.    eval("twr" + i).onRollOut = buttonsRollOut;
  931.    i++;
  932. }
  933. msg1 = "Instructions";
  934. msg2 = "Choose towers using buttons and place them on the map. Then press START";
  935. _root.attachMovie("cursor","cursor",_root.getNextHighestDepth());
  936. cursor.onEnterFrame = cursorMove;
  937. cursor._visible = false;
  938. tower0.onEnterFrame = towerMove;
  939. mainSound = new Sound(this);
  940. mainSound.setVolume(100);
  941. onEnterFrame = function()
  942. {
  943.    if((currentCreepWave == 4 || currentCreepWave == 10 || currentCreepWave == 17 || currentCreepWave == 25 || currentCreepWave == 33 || currentCreepWave == 45) && allDead == true && zast == false && rp > 0)
  944.    {
  945.       zast = true;
  946.       pausee = true;
  947.       animationsNum--;
  948.       attachMovie("animationsss","anim",_root.getNextHighestDepth());
  949.    }
  950.    currentGroupHealth = groupHealth[creatureGroupNum - 1];
  951.    costPerUnit = creatureCost[creatureGroupNum - 1];
  952.    i = 1;
  953.    while(i < _root.creatureNum)
  954.    {
  955.       eval("a" + i).loop();
  956.       i++;
  957.    }
  958.    availableorNot();
  959.    if(rp <= 0)
  960.    {
  961.       rp = 20;
  962.       snsr.swapDepths(99999);
  963.       snsr.removeMovieClip();
  964.       gotoAndStop("gameOver");
  965.       play();
  966.    }
  967. };
  968. stop();
  969.